<template>
	<view>
		<view style="position: fixed;top: 0;left: 0;right: 0;z-index: 99999;margin-top: 10%;">
			<!-- 搜索框 -->
			<!-- <uni-section class="section" title=""> -->
			<view style="height: 50px;background-color: #fff;">
				<uni-search-bar @confirm="search" :focus="false" v-model="searchValue" placeholder="输入学生姓名" />
			</view>
			<!-- </uni-section> -->

			<!-- 分段器 -->
			<view class="uni-padding-wrap uni-common-mt">
				<uni-segmented-control :current="current" :values="items" :style-type="styleType"
					:active-color="activeColor" @clickItem="onClickItem" />
			</view>
		</view>
		<view class="content" style="margin-top: 25%;">
			<!-- <uni-table class="tb1" ref="table" :loading="loading" emptyText="" @selection-change="selectionChange"> -->
			<!-- 显示还未进行审核的内容 -->

			<view v-if="current === 0">
				<view v-for="(item, index) in tableData" :key="index">
					<!-- <uni-card v-if="item.adminResult == 0" :title="item.instrumentName" extra="待审核"> -->
					<uni-card v-if="item.assistResult == 0 && item.note1 == 0&&item.auditStatus == 0" :title="item.instrumentName" extra=">"
						@click="check(item.id)">
						<view class="interval">
							<text class="card-text-name">姓名：{{item.name}}</text>
							<text class="card-text">学号/工号：{{item.studentId}}</text>


						</view>
						<view class="interval">
							<text class="card-text-name">设备类型：{{exchange(item.equipmentType)}}</text>
							<text class="card-text">提交时间：{{item.sbumitTime}}</text>
						</view>
						<view class="interval">
							<text class="card-text">预约时间：{{item.appointmentStart}}~{{item.appointmentEnd}}</text>
						</view>
						<!-- <text class="card-text">开始使用时间：{{item.appointmentStart}}</text><br>
							<text class="card-text">结束使用时间：{{item.appointmentEnd}}</text> -->

						<view class="check-mark">
							<text class="inx">序号.{{indexMethod(index)}}</text>
							<text class="msg-tag wait">待审核</text>
							<!-- <uni-icons type="forward" size="10" class="ico"></uni-icons> -->
						</view>
					</uni-card>
				</view>
			</view>
			<!-- 显示已通过审核的内容 -->
			<view v-if="current === 1">
				<view v-for="(item, index) in tableData" :key="index">
					<!-- <uni-card v-if="item.adminResult == 1" :title="item.instrumentName" extra="审核通过"> -->
					<uni-card v-if="item.assistResult == 1" :title="item.instrumentName" extra=">"
						@click="check(item.id)">
						<view class="interval">
							<text class="card-text-name">姓名：{{item.name}}</text>
							<text class="card-text">学号/工号：{{item.studentId}}</text>

						</view>
						<view class="interval">
							<text class="card-text-name">设备类型：{{exchange(item.equipmentType)}}</text>
							<text class="card-text">审核时间：{{item.assistTime}}</text>
						</view>
						<view class="interval">
							<text class="card-text">预约时间：{{item.appointmentStart}}~{{item.appointmentEnd}}</text>
						</view>
						<view class="check-mark">
							<text class="inx">序号.{{indexMethod(index)}}</text>
							<text class="msg-tag pass" v-if="item.note1 == 0">已通过</text>
							<text class="msg-tag cancel" v-else-if="item.note1 == 1">已取消</text>

						</view>
					</uni-card>
				</view>
			</view>
			<!-- 显示未通过审核的内容 -->
			<view v-if="current === 2">
				<view v-for="(item, index) in tableData" :key="index">
					<!-- <uni-card v-if="item.adminResult == 2" :title="item.instrumentName" extra="审核未通过"> -->
					<uni-card v-if="item.assistResult == 2" :title="item.instrumentName" extra=">"
						@click="check(item.id)">
						<view class="interval">
							<text class="card-text-name">姓名：{{item.name}}</text>
							<text class="card-text">学号/工号：{{item.studentId}}</text>

						</view>
						<view class="interval">
							<text class="card-text-name">设备类型：{{exchange(item.equipmentType)}}</text>
							<text class="card-text">审核时间：{{item.assistTime}}</text>
						</view>
						<view class="interval">
							<text class="card-text">预约时间：{{item.appointmentStart}}~{{item.appointmentEnd}}</text>
						</view>
						<view class="check-mark">
							<text class="inx">序号.{{indexMethod(index)}}</text>
							<text class="msg-tag error" v-if="item.note1 == 0">未通过</text>
							<text class="msg-tag cancel" v-if="item.note1 == 1">已取消</text>

						</view>
					</uni-card>
				</view>
			</view>
			<!-- </uni-table> -->
			<view class="uni-pagination-box" v-if="tableData.length!=0">
				<!-- 分页 -->
				<uni-pagination show-icon :page-size="pageSize" :current="pageCurrent" :total="total"
					v-model="pageCurrent" @change="change" />
			</view>
			<view v-if="tableData.length==0">
				<uni-table style="margin-left:4% ;margin-right:4% ; width: 92% ;" ref="table" :loading="loading"
					emptyText="暂无审核数据"></uni-table>
			</view>
			<view style="height: 20px;"></view>
		</view>

	</view>
</template>


<script>
	import {
		listAppointment
	} from "@/api/module/whd/appointment.js"



	export default {
		data() {
			return {
				// 参数
				queryParams: {
					pageNum: 1,
					pageSize: 4,
					studentId: null,
					department: null,
					name: null,
					gender: null,
					phone: null,
					idCard: null,
					teacherName: null,
					teacherId: null,
					assistName: null,
					assistId: null,
					equipmentType: null,
					applicationDepartment: null,
					instrumentId: null,
					instrumentName: null,
					modelNumber: null,
					specification: null,
					unitPrice: null,
					classifyNumber: null,
					purchaseDate: null,
					receiverId: null,
					receiverName: null,
					manufacturers: null,
					storageDate: null,
					storageLocation: null,
					expenditureSubject: null,
					useDirection: null,
					firstUse: null,
					appointmentStart: null,
					appointmentEnd: null,
					sbumitTime: null,
					auditStatus: 0,
					teacherResult: null,
					assistResult: 0,
					adminResult: null,
					teacherTime: null,
					adminTime: null,
					assistTime: null,
					userId: null,
					deptId: null,
					createBy: null,
					createTime: null,
					updateBy: null,
					updateTime: null,
					remark: null,
					note1: 0,
					note2: null,
					note3: null,
					note4: null,
					note5: null,
					note6: null,
					note7: null,
					note8: null,
					note9: null,
					note10: null
				},
				typelist: [],
				tableData: [],
				// 数据总量
				total: 0,
				equipTotal: 0,
				// 遮罩层
				loading: false,
				// 弹出层标题
				title: "",
				// 是否显示弹出层
				open: false,
				// 表单参数
				form: {},
				dict: {},
				// 新增内容
				// 分段标题
				items: ['未审核', '已通过', '未通过'],
				// 分段颜色
				activeColor: '#007aff',
				// 分段方式（文本：text；按钮：button）
				styleType: 'text',
				// 页面
				current: 0,
				// 搜索框输入
				searchValue: '',
				tableData: [],
				// 每页数据量
				pageSize: 4,
				// 当前页
				pageCurrent: 1,
				current: 0,
				// 数据总量
				total: 0,
				styleType: 'text',
				loading: false
			}
		},
		// 生成时
		created() {

			this.getDicts("yh_equip_type").then(res => {
				this.typelist = res.data
				console.log(this.typelist)
				for (var i = 0; i < this.typelist.length; i++) {
					this.dict[this.typelist[i].dictValue] = this.typelist[i].dictLabel
				}
				this.getList();
			});
		},
		onBackPress(options) {
			let self = this;
			if (options.from === 'navigateBack') {
				return false;
			}
			console.log("要指定返回的页面");
			uni.switchTab({
				url: '/pages/work/index'
			})
			return true;
		},
		// 方法
		methods: {
			//显示转换
			exchange(key) {
				return this.dict[key]
			},
			// 查库
			getList() {
				this.loading = true;
				listAppointment(this.queryParams).then(res => {
					this.tableData = res.rows;
					this.total = res.total;
					this.loading = false;
					/* console.log(this.tableData); */
				});
			},

			// 审核
			check(ids) {
				// console.log("被点了")
				const id = ids
				// console.log(ids)
				this.$tab.navigateTo('/pages/module/whd/review?id=' + ids)
			},

			// 查询按钮
			handleQuery() {
				// this.queryParams.pageNum = 1;
				// this.pageCurrent = 1;
				// if (this.flag) {
				// 	this.queryParams.auditStatus = this.value;
				// 	this.queryParams.adminResult = this.value;
				// };
				this.pageCurrent = 1
				this.queryParams.pageNum = 1
				this.getList();
			},
			// 分页触发
			change(e) {
				/* this.$refs.table.clearSelection()
				this.selectedIndexs.length = 0 */
				console.log(e)
				this.queryParams.pageNum = e.current
				this.getList(e.current)
			},
			indexMethod(index) {
				/* console.log((this.pageCurrent-1)*this.pageSize+index+1) */
				return (this.pageCurrent - 1) * this.pageSize + index + 1
			},
			// 新增内容
			// 切换字段
			onClickItem(e) {
				if (this.current !== e.currentIndex) {
					this.current = e.currentIndex
				}
				if (this.current != 0) {
					this.queryParams.note1 = null
				} else {
					this.queryParams.note1 = 0
				}
				console.log(this.current)
				this.queryParams.assistResult = this.current
				this.queryParams.auditStatus = this.current
				this.pageCurrent = 1
				this.queryParams.pageNum = 1
				this.getList()
			},
			search(res) {
				this.queryParams.name = res.value;
				this.handleQuery();
			}
		},
	}
</script>


<style lang="scss">
	/* ::v-deep.tb1{
		background-color: #18bc37;
	} */
	.section {
		// margin-top: -5%;
	}


	.uni-section-header {
		padding: 0px;
	}


	.uni-common-mt {
		background-color: #fff;
		// margin-top: 30px;
	}

	.uni-padding-wrap {
		// width: 750rpx;
		padding: 0px 30px;
	}

	.content-text {
		font-size: 14px;
		color: #666;
	}

	.content {
		text-align: center;
		font-weight: bold;
	}

	.inx {
		font-weight: normal;
		color: #000000;
	}

	.card-text {
		font-weight: normal;
		color: #000000;
	}

	.card-text-name {


		font-weight: normal;
		margin-right: 5%;
		color: #000000;
	}

	.interval {
		margin-bottom: 10px;
	}

	.check-mark {
		display: block;
		text-align: left;
	}

	.msg-tag.wait {
		background: #007aff;
		font-weight: normal;
		margin-left: 65%;
	}

	.msg-tag.pass {
		background: #18bc37;
		font-weight: normal;
		margin-left: 65%;
	}

	.msg-tag.error {
		background: #eb547c;
		font-weight: normal;
		margin-left: 65%;
	}

	.msg-tag.cancel {
		background: #eb0000;
		font-weight: normal;
		margin-left: 65%;
	}

	.msg-tag {
		position: relative;
		color: #fff;
		text-transform: uppercase;
		padding: 3px 10px;
		font-size: 10px;
		border-radius: 50px;
	}
</style>
